package com.feiyuan.core.controller.admin;

import com.feiyuan.common.exception.BusinessException;
import com.feiyuan.common.result.R;
import com.feiyuan.core.pojo.entity.AdminMenu;
import com.feiyuan.core.service.AdminMenuService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 后台页面左侧菜单导航
 */
@RestController
@RequestMapping("/admin/core/navigation")
public class AdminNavigationController {

    @Autowired
    private AdminMenuService menuService;

    /**
     * 查询菜单导航
     * @return
     */
    @GetMapping("/menu")
    public R menu(HttpServletRequest request) {
        String adminToken = request.getHeader("ADMIN_TOKEN");
        if (StringUtils.isEmpty(adminToken)) {
            throw new BusinessException("请重新登陆", 10010);
        }
        List<AdminMenu> menus = menuService.selectNavigations(adminToken);
        return R.ok().data("menus", menus);
    }
}
